package com.example.task1.ui.AllService.hospital;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.HospitalUserManagerBean;
import com.example.task1.ui.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

public class HospitalUserManagerAdapter extends BaseAdapter<HospitalUserManagerBean.RowsDTO> {

    private Context context;
    private int log;
    private List<HospitalUserManagerBean.RowsDTO> mData = new ArrayList<>();
    private TextView tvUserName;
    private TextView tvAddress;
    private TextView tvBirthday;
    private TextView tvCardId;
    private TextView tvSex;
    private TextView tvTel;

    public HospitalUserManagerAdapter(Context context, int log) {
        this.context = context;
        this.log = log;
    }

    @Override
    protected void setData(List<HospitalUserManagerBean.RowsDTO> rows) {
        mData.clear();
        mData = rows;
        notifyDataSetChanged();
    }

    @Override
    protected int getLayout() {
        return R.layout.hospitalusermanager;
    }

    @Override
    protected Context getContext() {
        return null;
    }

    @Override
    protected List<HospitalUserManagerBean.RowsDTO> getData() {
        return mData;
    }

    @Override
    protected void onBind(myHolder holder, HospitalUserManagerBean.RowsDTO date) {
        tvUserName.setText(date.getName());
        tvAddress.setText(date.getAddress());
        tvBirthday.setText(date.getBirthday());
        tvCardId.setText(date.getCardId());
        tvTel.setText(date.getTel());
        tvSex.setText(date.getName() == "0" ? "男" : "女");
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (log == 1) {
                    MyApplication.Hospital.userDate = date;
                    ((HospUserManagerActivity)context).finish();
                }else {
                    MyApplication.Hospital.userDate = date;
                    MyApplication.intent(context,HospitalUserModificationActivity.class);
                }
            }
        });
    }

    @Override
    protected void holder(View itemView) {
        initView(itemView);
    }

    private void initView(View view) {
        tvUserName = (TextView) view.findViewById(R.id.tv_userName);
        tvAddress = (TextView) view.findViewById(R.id.tv_address);
        tvBirthday = (TextView) view.findViewById(R.id.tv_birthday);
        tvCardId = (TextView) view.findViewById(R.id.tv_cardId);
        tvSex = (TextView) view.findViewById(R.id.tv_sex);
        tvTel = (TextView) view.findViewById(R.id.tv_tel);
    }
}
